package com.jc.demo.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;


@SuppressWarnings("Duplicates")
public class QueryDataDemo {

    public static void main(String[] args) throws IOException {
        // Instantiating Configuration class
        Configuration config = HBaseConfiguration.create();

        // Instantiating HTable class
        Connection connection = ConnectionFactory.createConnection(config);
        Table hTable = connection.getTable(TableName.valueOf("emp"));
        try {


            // Instantiating Get class
            Get g = new Get(Bytes.toBytes("row1"));

            // Reading the data
            Result result = hTable.get(g);


            // Reading values from Result class object
            byte [] value = result.getValue(Bytes.toBytes("personal"),Bytes.toBytes("name"));

            byte [] value1 = result.getValue(Bytes.toBytes("personal"),Bytes.toBytes("city"));

            // Printing the values
            String name = Bytes.toString(value);
            String city = Bytes.toString(value1);

            System.out.println("name: " + name + " city: " + city);


        } finally {
            hTable.close();
            connection.close();
        }

    }
}
